package cn.kgc.jdbc;

import cn.kgc.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author mosin
 * date 2022/2/10
 * @version 1.0
 * 使用jdbc修改数据库中的数据
 */
public class JDBCDemo06 {


    public static void main(String[] args) {
        Connection connection = null;
        Statement stmt = null;
        try {
            connection = JDBCUtil.getConnection();
            stmt = connection.createStatement();
            // 4.编写sql  发送sql  DML insert  delete  update
            String sql = "update user set username = '李四',pwd='666666',role=2 where id = 36";
            int i = stmt.executeUpdate(sql);
            System.out.println("line= " + i);
            // 5. 处理结果集  DQL
        } catch (Exception e) {
            e.printStackTrace();
        } finally {  // 6. 释放资源
            JDBCUtil.closeAll(null, stmt, connection);
        }
    }
}